/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.logist;

import dp1.titandevelop.titano.persistent.Cotizacion;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author chrestean
 */
public class ModulosT_LOG_DetalleCotizacion extends javax.swing.JInternalFrame {

    /**
     * Creates new form TitanoInternalSegADMUserNew
     */
    private AbstractTableModel model = new AbstractTableModel() {
        @Override
        public int getRowCount() {
            return cotizacion.getDetalleCotizacionArray().size();

        }

        @Override
        public int getColumnCount() {
            return 4;
        }

        @Override
        public boolean isCellEditable(int fi, int co) {
            switch (co) {
                case 2:
                    return true;
            }
            return false;
        }

        @Override
        public Object getValueAt(int fi, int co) {
            switch (co) {
                case 0:
                    return cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getToProducto().getDescripcion();
                case 1:
                    return new DecimalFormat("#.##").format(cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getCantidad());
                case 2:
                    return cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getToProducto().getUm();
                case 3:
                    return "S./"+cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getToProducto().getCosto();
                case 4:
                    return "S./"+ new DecimalFormat("#.##").format(cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getCantidad() * cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getToProducto().getCosto());

            }
            return null;
        }

        @Override
        public void setValueAt(Object value, int fi, int co) {
            switch (co) {
                case 3:
                    cotizacion.getDetalleCotizacionArray().get(fi).getToRequerimientoXProducto().getToProducto().setCosto(Float.parseFloat((String) value));
                    float suma = 0;
                    for (int i = 0; i < cotizacion.getDetalleCotizacionArray().size(); i++) {
                        suma += cotizacion.getDetalleCotizacionArray().get(i).getCantidad() * cotizacion.getDetalleCotizacionArray().get(i).getToRequerimientoXProducto().getToProducto().getCosto();
                    }

                    txtMontoTot.setText("" + new DecimalFormat("#.##").format(suma).toString()
                            );
                    this.fireTableDataChanged();

            }
        }

        @Override
        public String getColumnName(int col) {
            String[] titles = {"Producto", "Cantidad", "Unidades","Precio Unitario (S/.)", "Precio (S/.)"};
            return titles[col];
        }
    };
    private AdministrarCotizaciones caller = null;

    ModulosT_LOG_DetalleCotizacion(AdministrarCotizaciones caller, Cotizacion c) {
        this.initComponents();
        this.caller = caller;
        this.cotizacion = c;
        SimpleDateFormat formatoDeFecha = new SimpleDateFormat("dd/MM/yyyy");
                String fecha2=formatoDeFecha.format(this.cotizacion.getFecharecepcion());
        this.txtProveedor.setText("" + this.cotizacion.getIdcotizacion());
        this.txtFechaRecepcion.setText(""+fecha2);
        //this.datePkFechaRecepcion.setDate(this.cotizacion.getFecharecepcion());
        this.model.fireTableDataChanged();
        this.txtIdRequerimiento.setText(""+this.cotizacion.getIdcotizacion());
        this.txtProveedor2.setText(this.cotizacion.getToProveedor().getRazonsocial());
        this.jTable1.setModel(model);

        float suma = 0;
        for (int i = 0; i < cotizacion.getDetalleCotizacionArray().size(); i++) {
            suma += cotizacion.getDetalleCotizacionArray().get(i).getCantidad() * cotizacion.getDetalleCotizacionArray().get(i).getToRequerimientoXProducto().getToProducto().getCosto();
        }
       

        txtMontoTot.setText("" + new DecimalFormat("#.##").format(cotizacion.getPreciototal()).toString());
        this.model.fireTableDataChanged();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtProveedor = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txtIdRequerimiento = new javax.swing.JTextField();
        txtProveedor2 = new javax.swing.JTextField();
        txtFechaRecepcion = new javax.swing.JTextField();
        btnSalir = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        txtMontoTot = new javax.swing.JTextField();

        setTitle("Detalle Cotizacion");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos De Distribuidor"));
        jPanel1.setFont(new java.awt.Font("Tekton Pro", 0, 11)); // NOI18N

        jLabel3.setText("Id Cotización");

        jLabel5.setText("Fecha de Recepción");

        jLabel9.setText("Id Requerimiento");

        txtProveedor.setEnabled(false);

        jLabel10.setText("Proveedor");

        txtIdRequerimiento.setEnabled(false);

        txtProveedor2.setEnabled(false);

        txtFechaRecepcion.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtProveedor, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
                    .addComponent(txtFechaRecepcion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addGap(42, 42, 42)
                        .addComponent(txtProveedor2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtIdRequerimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(txtIdRequerimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel10)
                            .addComponent(txtFechaRecepcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtProveedor2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(9, 9, 9))
        );

        btnSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cancelar.png"))); // NOI18N
        btnSalir.setToolTipText("Salir");
        btnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Cotización de Productos", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID Producto", "Producto", "Cantidad", "Monto"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jLabel1.setText("Monto Total");

        txtMontoTot.setEnabled(false);
        txtMontoTot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtMontoTotActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtMontoTot, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 554, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtMontoTot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(97, 97, 97)
                        .addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(8, 8, 8))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(btnSalir)
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private Cotizacion cotizacion = null;

    private void txtMontoTotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtMontoTotActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtMontoTotActionPerformed

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
        // TODO add your handling code here:
        this.caller.show();
        this.dispose();
    }//GEN-LAST:event_btnSalirActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField txtFechaRecepcion;
    private javax.swing.JTextField txtIdRequerimiento;
    private javax.swing.JTextField txtMontoTot;
    private javax.swing.JTextField txtProveedor;
    private javax.swing.JTextField txtProveedor2;
    // End of variables declaration//GEN-END:variables
}
